#include "aephaseinfotab.h"
#include <QHeaderView>
#include <QHBoxLayout>
#include <QString>
#include "aephasefeature.h"

AEPhaseInfoTab::AEPhaseInfoTab(QWidget *parent)
    : MapInfoTab{parent}
    , m_aePhaseFeature{std::make_shared<AEPhaseFeature>()}
    , m_pChartBox{new QGroupBox("AE相位图谱数据")}
    , m_pChartData{new QTextEdit}
    , m_pMainLayout{new QHBoxLayout(this)}
    , m_pLayout{new QHBoxLayout()}
{
    // 设置主布局
    m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    m_pMainLayout->setSpacing(0);

    // 初始化Feature组件的UI并添加到布局
    m_aePhaseFeature->initUI(this);
    addFeature(m_aePhaseFeature);

    // 创建图表数据区域
    m_pChartData->setReadOnly(true);
    m_pChartData->setMinimumWidth(300);
    m_pChartData->setMinimumHeight(400);

    QVBoxLayout* pChartLayout = new QVBoxLayout(m_pChartBox);
    pChartLayout->addWidget(m_pChartData);
    pChartLayout->setContentsMargins(10, 10, 10, 10);

    m_pLayout->addWidget(m_pChartBox);
    m_pLayout->setContentsMargins(0, 0, 0, 0);

    m_pMainLayout->addLayout(m_pLayout);
    setLayout(m_pMainLayout);
}

AEPhaseInfoTab::~AEPhaseInfoTab()
{
    // UI元素会随父对象自动删除
}

void AEPhaseInfoTab::setDataTypeCode(uint8_t code)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDataTypeCode(code);
    }
}

void AEPhaseInfoTab::setDataLength(int32_t length)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDataLength(length);
    }
}

void AEPhaseInfoTab::setCreateTime(const QString& time)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setCreateTime(time);
    }
}

void AEPhaseInfoTab::setChartProperty(const DataSpecificationGW::SpectrumCharacter& property)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setChartProperty(property);
    }
}

void AEPhaseInfoTab::setDeviceName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDeviceName(name);
    }
}

void AEPhaseInfoTab::setDeviceCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDeviceCode(code);
    }
}

void AEPhaseInfoTab::setMeasurementName(const QString& name)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setMeasurementName(name);
    }
}

void AEPhaseInfoTab::setMeasurementCode(const QString& code)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setMeasurementCode(code);
    }
}

void AEPhaseInfoTab::setChannelFlag(int64_t flag)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setChannelFlag(flag);
    }
}

void AEPhaseInfoTab::setDataType(uint8_t type)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDataType(type);
    }
}

void AEPhaseInfoTab::setAmplitudeUnit(uint8_t unit)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setAmplitudeUnit(unit);
    }
}

void AEPhaseInfoTab::setAmplitudeLowerLimit(float lowerLimit)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setAmplitudeLowerLimit(lowerLimit);
    }
}

void AEPhaseInfoTab::setAmplitudeUpperLimit(float upperLimit)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setAmplitudeUpperLimit(upperLimit);
    }
}

void AEPhaseInfoTab::setUltrasonicSensorType(float type)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setUltrasonicSensorType(type);
    }
}

void AEPhaseInfoTab::setDataPointCount(int32_t count)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDataPointCount(count);
    }
}

void AEPhaseInfoTab::setDischargeTypeProbability(const QString& probability)
{
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setDischargeTypeProbability(probability);
    }
}

void AEPhaseInfoTab::setReservedData(const QByteArray& byte)
{
    // 数据会通过特性组件显示
    if (m_aePhaseFeature) {
        m_aePhaseFeature->setReservedData(byte);
    }
}

void AEPhaseInfoTab::setAEPhaseChartData(const QByteArray& data)
{
    m_pChartData->setText(data.toHex());
}
